<!--
- File:    按任务类型分类.
-->
<template>
  <div class="Web_Box">
    <div class=" bg_fff pt20">
      <div class=" pl20 pr20">
        <div class="watering_list" v-for="task in taskList">
          <div class="watering">
            <i class="iconfont icon-shuidi1"></i><span>{{task.ta_type_name}}</span><a class="water_btn" @click="actionBatch(task)">批量完成</a>
          </div>
          <div class="graden_cont4">
            <ul class="f-cb">
              <li v-for="plant in task.plant">
                <div class="graden_bg4" @click="toggleSelect(plant)">
                  <img :src="(plant.flower_image || plant.m_goods_image) ? $config.imgsite + $config.uploadImgSrc + (plant.flower_image || plant.m_goods_image) + '_w200' : defaultPlantImg">
                  <i class="iconfont icon-xuanze" v-show="plant.selected"></i>
                </div>
                <h3>{{plant.flower_name || plant.m_name}}</h3>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <div class="buttonfinish" @click="allBatch"><a>一键完成任务</a></div>
  </div>
</template>

<script>
  import {mapModules} from 'vuet'

  export default{
    mixins: [
      mapModules({taskIdListTmp: 'taskIdListTmp'})
    ],
    data() {
      return {
        defaultPlantImg: require('../../../assets/images/demo/xinqing2.png'),
        taskList: []
      }
    },
    created() {
      this.getTaskList()
    },
    methods: {
      actionBatch(task) {
        let selectedList = []
        for (let i = 0; i < task.plant.length; i++) {
          selectedList.push(task.plant[i].mt_id)
        }
        if (selectedList.length <= 0) {
          this.$toast('请选择植物')
          return
        }
        this.taskIdListTmp = selectedList
        this.$router.push({name: 'task-batch'})
      },
      allBatch() {
        let selectedList = []
        for (let i = 0; i < this.taskList.length; i++) {
          for (let j = 0; j < this.taskList[i].plant.length; j++) {
            if (this.taskList[i].plant[j].selected) {
              selectedList.push(this.taskList[i].plant[j].mt_id)
            }
          }
        }
        if (selectedList.length <= 0) {
          this.$toast('请选择植物')
          return
        }
        this.taskIdListTmp = selectedList
        this.$router.push({name: 'task-batch'})
      },
      toggleSelect(plant) {
        plant.selected = !plant.selected
      },
      getTaskList() {
        this.$request.getTaskGroupByAction().then(data => {
          for (let i = 0; i < data.length; i++) {
            for (let j = 0; j < data[i].plant.length; j++) {
              this.$set(data[i].plant[j], 'selected', true)
            }
          }
          this.taskList = data
        })
      }
    }
  }
</script>

<style>

</style>